package edu.buaa.act.travel.m.adapter;

import java.util.List;

import edu.buaa.act.travel.m.R;
import edu.buaa.act.travel.m.data.TripSimp;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TripAdapter extends BaseAdapter {
	
	private List<TripSimp> mTripList;
	private Activity mActivity;
	
	public TripAdapter(final Activity act, final List<TripSimp> trips) {
		mActivity = act;
		mTripList = trips;
	}

	@Override
	public int getCount() {
		return mTripList.size();
	}

	@Override
	public Object getItem(int position) {
		return mTripList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null) {
			convertView = mActivity.getLayoutInflater().inflate(R.layout.item_trip, null);
		}
		
		final TripSimp trip = mTripList.get(position);
		final TextView tripName = (TextView) convertView.findViewById(R.id.text_trip);
		tripName.setText(trip.getName());
		
		return convertView;
	}

}
